package com.cskaoyan.controller.promotion_controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.bo.TopicBatchDeleteBO;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.bean.vo.promotion_vo.TopicListVO;
import com.cskaoyan.bean.vo.promotion_vo.TopicReadVO;
import com.cskaoyan.service.promotion_service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description：
 * @author: 曹旭
 * @date: 2022/5/7 15:24
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    /**
     * 显示专题信息
     *
     * @param baseParam
     * @param title
     * @param subtitle
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo topicList(BaseParam baseParam, String title, String subtitle) {
        TopicListVO listVO = topicService.topicList(baseParam, title, subtitle);
        return BaseRespVo.ok(listVO);
    }

    /**
     * 新增专题
     * @param topic
     * @return
     */
    @PostMapping("create")
    public BaseRespVo createTopic(@RequestBody Topic topic) {

        topic = topicService.createTopic(topic);
        if (topic == null) {
            return BaseRespVo.errnoAndData("添加失败");
        }
        return BaseRespVo.out();
    }

    /**
     * 单个删除专题
     */
    @PostMapping("delete")
    public BaseRespVo deleteTopic(@RequestBody Topic topic) {
        topicService.deleteTopic(topic);
        return BaseRespVo.out();
    }

    /**
     * 批量删除专题
     * @param batchDeleteBO
     * @return
     */
    @PostMapping("batch-delete")
    public BaseRespVo batchDeleteTopic(@RequestBody TopicBatchDeleteBO batchDeleteBO) {
        topicService.batchDeleteTopic(batchDeleteBO);
        return BaseRespVo.out();
    }

    /**
     * 查看专题
     * @param id
     * @return
     */
    @GetMapping("read")
    public BaseRespVo readTopic(Integer id) {
        TopicReadVO topicReadVO = topicService.readTopic(id);
        return BaseRespVo.ok(topicReadVO);
    }

    /**
     * 更新专题
     * @param topic
     * @return
     */
    @PostMapping("update")
    public BaseRespVo updateTopic(@RequestBody Topic topic) {
        topic = topicService.updateTopic(topic);
        return BaseRespVo.ok(topic);
    }
}
